#include<stdio.h>
//
//顺序栈基本运算算法
#include <stdio.h>
#include <malloc.h>
#define MaxSize 100
typedef char ElemType;
typedef struct 
{	
	ElemType data[MaxSize];
	int top1;
	int top2;//栈指针
} DoubleStack;					//顺序栈类型
void InitStack(DoubleStack *&s)
{
	s=(DoubleStack *)malloc(sizeof(DoubleStack));
	s->top1=-1;
	s->top2 = MaxSize;
	
} 

void Push(DoubleStack *&s,int stackNumber,ElemType e)
{
	if(s->top1+1==s->top2)
	{
		printf("栈满！\n");
		return;
	}
	if(stackNumber==1)
	{
		s->data[++(s->top1)] = e;
	}
	else if(stackNumber==2)
	{
		s->data[--(s->top2)] = e;
	}
	else{
		printf("stackNumber err\n");
	}
	
	
}
void Pop(DoubleStack *&s,int stackNumber,ElemType &e)
{
	if(stackNumber==1)
	{
		if(s->top1==-1)
		{
			printf("第一个栈为空！\n");
			return;
		}
		e = s->data[(s->top1)--];
	}
	else if(stackNumber==2){
		if(s->top2==MaxSize)
		{
			printf("第二个栈为空！\n");
			return;
		}
		e = s->data[(s->top2)++];
	}
	else{
		printf("stackNumber err\n");
	}
} 

int main()
{
	DoubleStack* s;
	InitStack(s);
	Push(s,1,'a');
	Push(s,1,'b');
	Push(s,1,'c');
	Push(s,2,'d');
	ElemType e = 0;
	Pop(s,1,e);
	printf("栈1出栈：%c\n",e);
	Pop(s,2,e);
	printf("栈2出栈：%c\n",e);
	

	free(s);
	return 0;
}

